package com.pactera.madp.cp.controller.oms.workroom;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.workroom.WorkInternalGroupAddDTO;
import com.pactera.madp.cp.api.dto.workroom.WorkInternalGroupPageDTO;
import com.pactera.madp.cp.api.dto.workroom.WorkInternalGroupUpdateDTO;
import com.pactera.madp.cp.api.vo.workroom.WorkInternalGroupDetailsVO;
import com.pactera.madp.cp.api.vo.workroom.WorkInternalGroupListVO;
import com.pactera.madp.cp.api.vo.workroom.WorkInternalGroupPageVO;
import com.pactera.madp.cp.service.WorkInternalGroupService;
import com.pactera.madp.cp.service.impl.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * WorkInternalGroupContaoller
 *
 * @author jun
 * @version 1.0
 * 2021/8/30 9:46
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/work-internal-group")
@Api(value = "work-internal-group",tags = "企业内部群管理")
public class WorkInternalGroupController {

    private final WorkInternalGroupService workInternalGroupService;

    @SysLog("创建内部群")
    @PostMapping
    @ApiOperation(value = "创建内部群")
    public R<Boolean> saveWorkInternalGroup(@RequestBody WorkInternalGroupAddDTO dto){
        dto.setOwnerId(AccountService.getEmpId());
        return workInternalGroupService.saveWorkInternalGroup(dto) ? R.ok(Boolean.TRUE,"创建成功") : R.failed(Boolean.FALSE,"创建失败");
    }

    @SysLog("修改内部群聊")
    @PutMapping
    @ApiOperation(value = "修改内部群聊")
    public R<Boolean> updateWorkInternalGroup(@RequestBody WorkInternalGroupUpdateDTO dto){
        return workInternalGroupService.updateWorkInternalGroup(dto) ? R.ok(Boolean.TRUE,"修改成功") : R.failed(Boolean.FALSE,"修改失败");
    }

    @GetMapping("/page")
    @ApiOperation(value = "内部群分页查询")
    public R<Page<WorkInternalGroupPageVO>> getPage(WorkInternalGroupPageDTO dto, Page page){
        return R.ok(workInternalGroupService.getPage(page,dto));
    }

    @GetMapping("/list")
    @ApiOperation(value = "内部群列表")
    public R<List<WorkInternalGroupListVO>> getList(){
        return R.ok(workInternalGroupService.getList());
    }

    @GetMapping
    @ApiOperation(value = "获取群详情")
    public R<WorkInternalGroupDetailsVO> getDetails(Integer id){
        return R.ok(workInternalGroupService.getDetails(id));
    }

}
